import { defineStore } from 'pinia'
import { getLogin,getFindMy } from '@/api/login'
import { useStorage } from '@vueuse/core'
import router from '@/router'
export const useUserStore = defineStore('user', () => {
  const changeAdd = ref(true)
  const token = useStorage<string>('token', '')
  async function setLogin(val: object) {
    const res = await getLogin(val)
    token.value = res.token
    console.log(token.value)
  }
  function outLogin() {
    token.value = ''
    // resetRouter()
    // location.reload()
    router.replace({ path: '/login' })
  }
  const username = ref()

  return {
    token,
    changeAdd,
    setLogin,
    outLogin,
    username,
  }
})
